// js 是可变的
//  1. 变量可变
//  2. 引用赋值

let obj1 = {
    name:'daxia',
    arr:[1,[2,3],4]
}

let obj2 = obj1;
obj2.name = 'liuyu';

console.log(obj1,obj2);

// 浅拷贝
function shallowClone(source) {
    var target = {};
    for(var i in source) {
        if (source.hasOwnProperty(i)) {
            target[i] = source[i];
        }
    }
    return target;
}

const obj3 = shallowClone(obj1);
console.log(obj3);

// 深拷贝 消耗内存
let obj4 = JSON.parse(JSON.stringify(obj1));
obj4.arr[0] = 9;
console.log(obj4);

